<?php
namespace Home\Action;
use Common\Action\FirstendAction;
class BaseAction extends FirstendAction{
public function _initialize()
    {
	parent::_initialize();
	$this->assign('navlist',$this->nav());
	$this->tqkuid=C('yh_app_kehuduan');
	$this->assign('trackurl',$this->trackid());
	$tkapi=F('tqkapi/api');
	if(false ===$tkapi){
		$this->tqkapi = 'http://api.tuiquanke.com';
		}else{
		$this->tqkapi = $tkapi;
	}
		

	
	}
	

protected function nav(){
$where=array(
'status'=>1,
'type'=>'main'
);

$navlist=M('nav')->cache(true, 50 * 60)->field('name,alias,link,target')->where($where)->order('ordid asc')->select();
return $navlist;

}

    protected function trackid(){
        $track=I('t','0','number_int');
        $isagent=cookie('createagent');
        if((!empty($track) && $track!=$isagent && is_numeric($track)) || (false === $isagent && !empty($track) && is_numeric($track))){
        	$res=M('user')->field('webmaster_pid,pdd_pid')->where(array('id'=>$track))->find();
        	if($res){
        	$data=array(
        	't_pid'=>$res['webmaster_pid'],
        	'p_pid'=>$res['pdd_pid'],
        	't'=>$track,
        	);
        	$data=serialize($data);
       }
         cookie("trackid", $data, 86400 * 15);
         cookie('createagent',$track);
        }
        $trackid=cookie('trackid');
        if(!empty($trackid)){
        	$data=unserialize($trackid);
            $trackurl='?t='.$data['t'];
            return $trackurl;
        }
        
    if($this->visitor->is_login){
	$webmaster=$this->visitor->get();
	if($webmaster['tbname']==1){
	$data=array(
    	't_pid'=>$webmaster['webmaster_pid'],
    	'p_pid'=>$webmaster['pdd_pid'],
    	't'=>$webmaster['id'],
    	);
    	 $data=serialize($data);
    	 cookie("trackid", $data, 86400 * 15);
     $trackurl='?t='.$webmaster['id'];
      return $trackurl;
	}
	}

    }
	
	
	
}
	